package com.fast.develop.dm.core.xml.generator;

import com.fast.develop.dm.meta.MetaField;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * @author 莫寅
 * @createTime 2022-06-05 01:25
 * @desc：
 */
public class PropertyGenerator {

    private String name;
    private String notNull;
    private String length;
    private String type;

    private Document document;

    public PropertyGenerator(Document document, MetaField metaField) {
        this.name = metaField.getName();
        this.notNull = metaField.getRequired().booleanValue()+"";
        this.length = metaField.getLength()+"";
        this.type = metaField.getType().type();
        this.document = document;
    }


    /**
     *
     * <property name="title1" not-null="true" length="50" type="integer"/>
     * @return
     */
    public void generate(Node node){
        Element element = document.createElement("property");
        element.setAttribute("name", name);
        element.setAttribute("not-null", notNull);
        element.setAttribute("length", length);
        element.setAttribute("type", type);
        node.appendChild(element);
    }
}
